package br.ufmg.dcc.vod.remoteworkers.scheduler;

import junit.framework.TestCase;
import br.ufmg.dcc.vod.remoteworkers.Command;
import br.ufmg.dcc.vod.remoteworkers.ID;
import br.ufmg.dcc.vod.remoteworkers.Result;
import br.ufmg.dcc.vod.remoteworkers.scheduler.ProcessorEntry.ProcessorState;

public class ProcessorEntryTest extends TestCase {

	public void testAll() {
		ProcessorEntry pe = new ProcessorEntry();
		
		
		assertNull(pe.getCurrentCommand());
		assertEquals(ProcessorState.DOWN, pe.getState());
		
		pe.setDown();
		assertNull(pe.getCurrentCommand());
		assertEquals(ProcessorState.DOWN, pe.getState());
		
		pe.setIdle();
		assertNull(pe.getCurrentCommand());
		assertEquals(ProcessorState.IDLE, pe.getState());
		
		pe.setDown();
		assertNull(pe.getCurrentCommand());
		assertEquals(ProcessorState.DOWN, pe.getState());
		
		pe.setWorking(new FakeCommand());
		assertNotNull(pe.getCurrentCommand());
		assertEquals(ProcessorState.WORKING, pe.getState());
		
		pe.setDown();
		assertNull(pe.getCurrentCommand());
		assertEquals(ProcessorState.DOWN, pe.getState());
		
		pe.setWorking(new FakeCommand());
		assertNotNull(pe.getCurrentCommand());
		assertEquals(ProcessorState.WORKING, pe.getState());
		
		pe.setIdle();
		assertNull(pe.getCurrentCommand());
		assertEquals(ProcessorState.IDLE, pe.getState());
	}
	
	private class FakeCommand implements Command {

		@Override
		public ID getID() {
			return null;
		}

		@Override
		public Result process() throws Exception {
			return null;
		}
	}
}
